<?php
declare(strict_types=1);

namespace App\Resource\Streamer\Task;


use App\Enums\StreamerEnum;
use Illuminate\Http\Resources\Json\JsonResource;

class TemplateResource extends JsonResource
{
    public function toArray($request)
    {
        $count = $this->type == StreamerEnum::TASK_TYPE_ONLINE ? floor($this->count / 3600) : $this->count;
        $maxCount = $this->type == StreamerEnum::TASK_TYPE_ONLINE ? floor($this->max_count / 3600) : $this->max_count;
        $title = preg_replace('/{\$max_count}/', (string)$maxCount, $this->title);
        $desc = preg_replace('/{\$count}/',(string)$count, $this->desc);
        $desc = preg_replace('/{\$exp}/', (string)$this->exp, $desc);
        return [
            "id" => $this->id,
            "level" => $this->level,
            "title" => $title,
            "type" => $this->type,
            "period" => $this->period,
            "count" => $count,
            "max_count" => $maxCount,
            "exp" => $this->exp,
            "desc" => $desc,
        ];
    }
}